﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

/// <summary>
/// Summary description for HinhAnhCongTyProvider
/// Author CuongBH
/// CreatedDate 07/12/2011
/// </summary>
namespace EHTWebsite.Code
{
    public class HinhAnhCongTyProvider
    {
        public static Int32 IUHinhAnhCongTy(HinhAnhCongTy theHinhAnhCongTy, bool IsAdd)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_IUHinhAnhCongTys";
            command.CommandType = CommandType.StoredProcedure;
            SqlParameter theHinhAnhIDParameter = new SqlParameter();

            theHinhAnhIDParameter.ParameterName = "@HinhAnhIDOut";
            theHinhAnhIDParameter.Direction = ParameterDirection.Output;
            theHinhAnhIDParameter.DbType = DbType.Int32;

            command.Parameters.Add(theHinhAnhIDParameter);
            command.Parameters.Add(new SqlParameter("@HinhAnhID", theHinhAnhCongTy.HinhAnhID));
            command.Parameters.Add(new SqlParameter("@HinhAnhUrl", theHinhAnhCongTy.HinhAnhUrl));
            command.Parameters.Add(new SqlParameter("@MoTaVN", theHinhAnhCongTy.MoTaVN));
            command.Parameters.Add(new SqlParameter("@MoTaOther", theHinhAnhCongTy.MoTaOther));
            command.Parameters.Add(new SqlParameter("@NumberOfOrder", theHinhAnhCongTy.NumberOfOrder));
            command.Parameters.Add(new SqlParameter("@Publish", theHinhAnhCongTy.Publish));
            command.Parameters.Add(new SqlParameter("@IsAdd", IsAdd));

            DataProvider.ExecuteNoneQuery(command);

            return Int32.Parse(command.Parameters["@HinhAnhIDOut"].Value.ToString());
        }

        /// <summary>
        /// Author cuongBH
        /// CreatedDate 07/12/2011
        /// </summary>
        /// <param name="HinhAnhID"></param>
        public static void DeleteHinhAnhCongTyByHinhAnhID(Int32 HinhAnhID)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_DeleteHinhAnhCongTyByHinhAnhID";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@HinhAnhID", HinhAnhID));

            DataProvider.ExecuteNoneQuery(command);
        }

        /// <summary>
        /// Author : toanvt
        /// CreatedDate 06/02/2012
        /// Descriptin :lấy danh sách hình ảnh công ty cho Back End
        /// </summary>
        /// <returns></returns>
        public static DataSet GetHinhAnhCongTysForBackEnd(Int32 pageIndex, Int32 pageSize, out Int32 totalRecord)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_GetHinhAnhCongTysForBackEnd";
            command.CommandType = CommandType.StoredProcedure;

            command.Parameters.Add(new SqlParameter("@PageIndex", pageIndex));
            command.Parameters.Add(new SqlParameter("@PageSize", pageSize));

            return DataProvider.ExecuteDataSet(command, out totalRecord);
        }

        /// <summary>
        /// Author : toanvt
        /// CreatedDate 06/02/2012
        /// Descriptin : lấy danh sách hình ảnh công ty cho Front End
        /// </summary>
        /// <returns></returns>
        public static DataSet GetHinhAnhCongTysForFrontEnd(Int32 pageIndex, Int32 pageSize, out Int32 totalRecord)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_GetHinhAnhCongTysForFrontEnd";
            command.CommandType = CommandType.StoredProcedure;

            command.Parameters.Add(new SqlParameter("@PageIndex", pageIndex));
            command.Parameters.Add(new SqlParameter("@PageSize", pageSize));

            return DataProvider.ExecuteDataSet(command, out totalRecord);
        }

        /// <summary>
        /// Author toanvt
        /// CreatedDate 08/12/2011
        /// </summary>
        /// <param name="HinhAnhID">Mã hình ảnh</param>
        /// <param name="CongTyID">Mã công ty</param>
        /// <returns>HinhAnhCongTy</returns>
        public static HinhAnhCongTy GetHinhAnhCongTyByHinhAnhID(Int32 HinhAnhID)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_GetHinhAnhCongTyByHinhAnhID";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@HinhAnhID", HinhAnhID));

            DataSet ds = DataProvider.ExecuteDataSet(command);
            HinhAnhCongTy theHinhAnhCongTy = null;

            if (ds.Tables[0].Rows.Count > 0)
            {
                theHinhAnhCongTy = new HinhAnhCongTy();
                theHinhAnhCongTy.HinhAnhID = Int32.Parse(ds.Tables[0].Rows[0]["HinhAnhID"].ToString());
                theHinhAnhCongTy.HinhAnhUrl = ds.Tables[0].Rows[0]["HinhAnhUrl"].ToString();
                theHinhAnhCongTy.MoTaVN = ds.Tables[0].Rows[0]["MoTaVN"].ToString();
                theHinhAnhCongTy.MoTaOther = ds.Tables[0].Rows[0]["MoTaOther"].ToString();
                theHinhAnhCongTy.NumberOfOrder = Int32.Parse(ds.Tables[0].Rows[0]["NumberOfOrder"].ToString());
                theHinhAnhCongTy.Publish = Boolean.Parse(ds.Tables[0].Rows[0]["Publish"].ToString());
            }

            return theHinhAnhCongTy;
        }

        public static void ChangePublishByHinhAnhID(Int32 hinhAnhID)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_ChangePublishByHinhAnhID";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@HinhAnhID", hinhAnhID));
            DataProvider.ExecuteNoneQuery(command);
        }

        public static void UpdateNumberOfOrderByHinhAnhID(Int32 hinhAnhID, Int32 numberOfOrder)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_UpdateNumberOfOrderByHinhAnhID";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@HinhAnhID", hinhAnhID));
            command.Parameters.Add(new SqlParameter("@NumberOfOrder", numberOfOrder));
            DataProvider.ExecuteNoneQuery(command);
        }
    }
}